package cn.com.dashihui.web.service;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import cn.com.dashihui.kit.ExcelExportUtil;
import cn.com.dashihui.kit.ExcelExportUtil.Pair;
import cn.com.dashihui.web.dao.AuthDownload;

public class AuthDownloadService {
	
	public boolean save(AuthDownload newObject){
		return newObject.save();
	}
	

	
	public boolean update(AuthDownload object){
		return object.update();
	}
	
	
	public AuthDownload findById(int id){
		return AuthDownload.me().findFirst("SELECT a.* FROM t_auth_download a WHERE a.id=?",id);
	}
	
	public AuthDownload findByUserId(int userId){
		return  AuthDownload.me().findFirst("SELECT A.trueName,RO.alias,S.title  FROM t_auth_admin_seller A left join t_auth_admin_roles_seller R ON  R.userid=A.id  left join t_auth_roles_seller RO  ON  RO.id=R.roleid left join t_dict_store S on S.storeid=A.storeid  WHERE A.id=?",userId);
	}
	public Record findByUserId1(int userId){
		return  Db.findFirst("SELECT A.trueName,RO.alias,S.title  FROM t_auth_admin_seller A left join  "
				+ " t_auth_admin_roles_seller R ON  R.userid=A.id  left join t_auth_roles_seller RO  ON  RO.id=R.roleid left join t_dict_store S on S.storeid=A.storeid  WHERE A.id=?",userId);
	}
    /*
     * 查询登陆下载统计
     * @param pageNum
     * @param pageSize
     * @param id
     * @return
     */
	public Page<Record> findPage( int pageNum, int pageSize) {
		String sql="from t_auth_download  group by id order by id desc";
		return Db.paginate(pageNum, pageSize,"select * ",sql);
	}
    
	/*
     * 导出
     * @param pageNum
     * @param pageSize
     * @param id
     * @return
     */
	public List<Record> findPageExcel() {
		String sql="select * from t_auth_download  group by id order by id desc";
		return Db.find(sql);
	}
	
	public void exportVip(HttpServletResponse response, HttpServletRequest request, List<Pair> titles, List<Record> listz) {
		ExcelExportUtil.exportByRecord(response, request, "登陆下载统计", titles, listz);
	}
	
}
